/*
 * @Author: 徐建辰
 * @Date: 2022-02-12 15:00:08
 * @LastEditTime: 2022-02-14 17:17:44
 * @LastEditors: 徐建辰
 * @Description: 集中处理本地缓存
 */
import {TOKEN} from './constant'

// token
export const setToken = value => localStorage.setItem(TOKEN, value)
export const getToken = () => localStorage.getItem(TOKEN)
export const removeToken = () => localStorage.removeItem(TOKEN)

// 统一性存取删
export const setItem = (key, value) => {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  return localStorage.setItem(key, value)
}
export const getItem = key => {
  const data = localStorage.getItem(key)
  try {
    return JSON.parse(data)
  } catch (error) {
    return data
  }
}
export const removeItem = key => localStorage.removeItem(key)
export const removeAll = () => localStorage.clear()